package spzx.controller;

import com.atguigu.spzx.model.dto.product.CategoryBrandDto;
import com.atguigu.spzx.model.entity.product.CategoryBrand;
import com.atguigu.spzx.model.vo.common.Result;
import com.atguigu.spzx.model.vo.common.ResultCodeEnum;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import spzx.service.CategoryBrandService;
import spzx.service.CategoryService;

import java.util.List;

@RestController
@RequestMapping("/admin/categoryBrand")
public class CategoryBrandController {

    @Autowired
    private CategoryBrandService categoryBrandService;

    /**
     * 删除品牌分类接口
     * @param id
     */
     @DeleteMapping("deleteById/{id}")
     public Result deleteById(@PathVariable Long id){
         categoryBrandService.deleteById(id);
         return Result.build(null, ResultCodeEnum.SUCCESS);
     }

    /**
     * 更新品牌信息接口
     * @param categoryBrand
     */
    @PostMapping("updateCategoryBrand")
    public Result updateCategoryBrand(@RequestBody CategoryBrand categoryBrand){
        categoryBrandService.updateCategoryBrand(categoryBrand);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }

    /**
     * 根据第三级分类id查找品牌分类对应的ID集合，此集合中包含3个品牌分类的ID
     * @param category3Id
     * @return
     */
    @GetMapping("findCategoryIds/{category3Id}")
    public Result findCategoryIds(@PathVariable Long category3Id){
        List<Long> ids = categoryBrandService.findCategoryIds(category3Id);
        return Result.build(ids, ResultCodeEnum.SUCCESS);
    }

    /**
     * 添加品牌分类
     */
    @PostMapping("addCategoryBrand")
    public Result addCategoryBrand(@RequestBody CategoryBrand categoryBrand){
        categoryBrandService.addCategoryBrand(categoryBrand);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }


    /**
     * 查找所有的品牌分类
     *
     * @param pageNum
     * @param pageSize
     * @param categoryBrandDto
     * @return
     */
    @GetMapping("findByPage/{pageNum}/{pageSize}")
    public Result findByPage(@PathVariable Integer pageNum, @PathVariable Integer pageSize, CategoryBrandDto categoryBrandDto){
        PageInfo pageInfo = categoryBrandService.findByPage(pageNum, pageSize, categoryBrandDto);
        return Result.build(pageInfo, ResultCodeEnum.SUCCESS);
    }


}
